<template>
  <el-card shadow="hover" header="系统日志">
    <el-table
      :data="logList"
      style="width: 100%">
      <el-table-column
        type="index"
        label="序号"
        fixed="left">
      </el-table-column>
      <el-table-column
        prop="username"
        fixed="left"
        align="center"
        label="操作人">
      </el-table-column>
      <el-table-column
        prop="operation"
        fixed="left"
        label="操作">
      </el-table-column>
      <el-table-column
        prop="method"
        label="method">
      </el-table-column>
      <el-table-column
        prop="params"
        label="参数"
        width="220">
      </el-table-column>
      <el-table-column
        prop="ip"
        label="ip">
      </el-table-column>
      <el-table-column
        prop="createDate"
        label="时间">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </el-card>
</template>

<script>
  import {sysLog} from "../../api/app";
  import moment from "moment";

  export default {
    name: "log",
    data() {
      return {
        logList: [],
        pageIndex:1,
        pageSize: 10,
        currentPage: 1,
        total: 0,
      }
    },
    methods: {
      async getSysLog() {
        let res = await sysLog({pageIndex: this.currentPage, pageSize: this.pageSize});
        this.logList = res.logs.list;
        this.logList.map(v => {
          v.createDate = moment(v.createDate).format('YYYY-MM-DD HH:mm:ss')
        })
        this.total = res.logs.total;
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.currentPage = val;
        this.getSysLog();
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.currentPage = val;
        this.getSysLog();
      }
    },
    created() {
      this.getSysLog();
    }
  }
</script>

<style scoped>

</style>
